/* License Notice:
**
** This program is free software: you can redistribute it and/or modify
**    it under the terms of the GNU General Public License as published by
**    the Free Software Foundation, either version 3 of the License, or
**    (at your option) any later version.
** This program is distributed in the hope that it will be useful,
**   but WITHOUT ANY WARRANTY; without even the implied warranty of
**   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
**   GNU General Public License for more details.
** You should have received a copy of the GNU General Public License
**   along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
 * @file keyboard.hpp
 * @author TooOld2Rock'nRoll
 * @date 2024/05/03
 * @remark Last modified in 2024/05/03
 * @brief Interface for dealing with everything keyboard related.
 *
 * @todo For now we will use SDL's ids for keys and events in general, but it should be independent of the events API (create our own ids, etc).
 * @todo Listem for the event SDL_KEYMAPCHANGED as it may change the number of keys int he keyboard.
 */
#ifndef _KEYBOARD_HPP_
#define _KEYBOARD_HPP_

/*---- Includes ----*/
#include <cstring>
#include <stdexcept>
#include <fmt/core.h>

#include <SDL2/SDL_events.h>
#include <SDL2/SDL_keyboard.h>

#include "interfaces/input_device.hpp"


/*---- Class Declaration ----*/
/**
 * @brief Hardware keyboard abstraction.
 */
class Keyboard : public InputDevice<SDL_Scancode>
{
    private:
        ///Permanent pointer to SDL's array of keyboard keys.
        const volatile Uint8 *ui8a_sdl_keyboard_state = nullptr;
        ///The previous update keyboard state.
        volatile Uint8 *ui8a_save_keyboard_state = nullptr;

        ///Translate SLD keys to our keyboard_key
        volatile key_state *a_keyboard_state = nullptr;

        ///CTRL, ALT, etc, modifiers.
        ///@see https://wiki.libsdl.org/SDL2/SDL_Keymod
        volatile SDL_Keymod _key_modifiers = SDL_Keymod::KMOD_NONE;


    protected:


    public:
        Keyboard ();
        ~Keyboard ();

        virtual void update () override;

        virtual key_state getKeyState (SDL_Scancode scancode) const override;
        /** @brief Returns the modifier (CTRL, ALT, etc) keys state. */
        SDL_Keymod getKeyModifiers () const { return this->_key_modifiers; }
};//END Keyboard

#endif //_KEYBOARD_HPP_

